package com.xyzwps.mvckotlin.dao.repository

import com.xyzwps.mvckotlin.dao.mapper.IUserInfoMapper
import com.xyzwps.mvckotlin.dao.model.UserInfo
import kotlinx.coroutines.Deferred
import kotlinx.coroutines.async
import kotlinx.coroutines.coroutineScope
import org.springframework.stereotype.Repository

@Repository
class UserInfoRepository(val userInfoMapper: IUserInfoMapper) {

    suspend fun create(userInfo: UserInfo): Deferred<UserInfo> = coroutineScope {
        async {
            userInfoMapper.create(userInfo)
            userInfoMapper.getByUserId(userInfo.userId!!)
        }
    }

    suspend fun getByUsername(username: String): Deferred<UserInfo?> = coroutineScope {
        async {
            userInfoMapper.getByUsername(username)
        }
    }

}